<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta
            name="viewport"
            content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    >
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事件捕获和冒泡</title>
</head>
<body>
<div class="outer">
    <div class="inner">
        <button class="button">click</button>
    </div>
</div>
<script>
    const $ = (s) => document.querySelector(s);
    const outer = $('.outer');
    const inner = $('.inner');
    const button = $('.button');
    outer.addEventListener("click", function() {
        console.log("outer在捕获阶段监听到点击事件");
    }, true);
    inner.addEventListener("click", function() {
        console.log('inner在冒泡阶段监听到点击事件');
    });
    button.addEventListener("click", function(event) {
        event.stopPropagation(); // 阻止事件冒泡
        event.preventDefault();
        event.stopImmediatePropagation();
        console.log("按钮被点击");
    })
    
</script>
</body>
</html>